package com.sso.security.userdetail;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * @Author: TongRui乀
 * @Date: 2020-03-23 15:18
 * @description： 自定义的查询用户信息的逻辑
 */
@Slf4j
@Component
public class CustomerUserDetailService implements UserDetailsService {

    @Autowired
    private BCryptPasswordEncoder bCryptPasswordEncoder;

    @Override
    public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {

        log.info("当前{}用户正在查询用户信息", userName);

        String password = bCryptPasswordEncoder.encode("123456");

        return new User(userName, password, AuthorityUtils.commaSeparatedStringToAuthorityList("ADMIN"));
    }
}
